<?php
@session_start();
require_once("../../includes/config.inc.php"); 
require_once("../../includes/Database.class.php");
require_once("../../includes/GPSFunction.php");
 
$db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE); 
$db->connect(); 

function insertMeterData($devData)
{
	$db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE); 
	$db->connect(); 
	
	$devData = explode("#",$devData);
	
	$getLiveData = "SELECT * FROM tb_livegps_info WHERE tli_imei = '".$devData[0]."'";
	$exeLiveData = $db->query($getLiveData);
	if($db->affected_rows > 0)
	{
		$fetLiveData = $db->fetch_array($exeLiveData);
		//print_r($fetLiveData);
		$odoMeter = $fetLiveData[tli_distance];
		$lastData1=explode("#",$fetLiveData[tli_parameter]);
		$lastData2=explode("@",$lastData1[0]);
		$lvData = ($fetLiveData[tli_distance]+$devData[1]+$fetLiveData[tli_today]).','.$lastData2[1].','.$devData[2];
		return $lvData;
	}
}

//$_POST[devImei] = '40026599027#0';
if(isset($_POST[devImei]))
{
	$statusHTML = '<table width="100%">
		<tr>
			<th>Odometer</th><th>Location</th><th>Speed</th><th>Last Received</th>
		</tr>
		<tr>';
	$dStatus = explode(",",insertMeterData($_POST[devImei]));
	
	$res2=simpleGeocode(calLat($dStatus[3]),calLong($dStatus[2]));
	$res2=str_replace('"',"",$res2);
	$statusHTML .='<td>'.round($dStatus[0],2).'</td><td>'.$res2.'</td><td>'.$dStatus[4].'</td><td>'.$dStatus[9].' '.date("h:i:s A",strtotime($dStatus[10])).'</td>';
	$statusHTML .= '</table>';
}
print_r($statusHTML);

?>